package com.google.android.vending.expansion.downloader;

import android.content.Context;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.util.Log;
import com.android.vending.expansion.downloader.R.string;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Helpers
{
  private static final Pattern CONTENT_DISPOSITION_PATTERN = Pattern.compile("attachment;\\s*filename\\s*=\\s*\"([^\"]*)\"");
  public static Random sRandom = new Random(SystemClock.uptimeMillis());

  static void deleteFile(String paramString)
  {
    try
    {
      new File(paramString).delete();
      return;
    }
    catch (Exception localException)
    {
      Log.w("LVLDL", "file: '" + paramString + "' couldn't be deleted", localException);
    }
  }

  public static boolean doesFileExist(Context paramContext, String paramString, long paramLong, boolean paramBoolean)
  {
    File localFile = new File(generateSaveFileName(paramContext, paramString));
    if (localFile.exists())
    {
      if (localFile.length() == paramLong)
        return true;
      if (paramBoolean)
        localFile.delete();
    }
    return false;
  }

  public static String generateSaveFileName(Context paramContext, String paramString)
  {
    return getSaveFilePath(paramContext) + File.separator + paramString;
  }

  public static long getAvailableBytes(File paramFile)
  {
    StatFs localStatFs = new StatFs(paramFile.getPath());
    return (localStatFs.getAvailableBlocks() - 4L) * localStatFs.getBlockSize();
  }

  public static String getDownloadProgressPercent(long paramLong1, long paramLong2)
  {
    if (paramLong2 == 0L)
      return "";
    return Long.toString(100L * paramLong1 / paramLong2) + "%";
  }

  public static String getDownloadProgressString(long paramLong1, long paramLong2)
  {
    if (paramLong2 == 0L)
      return "";
    StringBuilder localStringBuilder1 = new StringBuilder();
    Object[] arrayOfObject1 = new Object[1];
    arrayOfObject1[0] = Float.valueOf((float)paramLong1 / 1048576.0F);
    StringBuilder localStringBuilder2 = localStringBuilder1.append(String.format("%.2f", arrayOfObject1)).append("MB /");
    Object[] arrayOfObject2 = new Object[1];
    arrayOfObject2[0] = Float.valueOf((float)paramLong2 / 1048576.0F);
    return String.format("%.2f", arrayOfObject2) + "MB";
  }

  public static String getDownloadProgressStringNotification(long paramLong1, long paramLong2)
  {
    if (paramLong2 == 0L)
      return "";
    return getDownloadProgressString(paramLong1, paramLong2) + " (" + getDownloadProgressPercent(paramLong1, paramLong2) + ")";
  }

  public static int getDownloaderStringResourceIDFromState(int paramInt)
  {
    switch (paramInt)
    {
    default:
      return R.string.state_unknown;
    case 1:
      return R.string.state_idle;
    case 2:
      return R.string.state_fetching_url;
    case 3:
      return R.string.state_connecting;
    case 4:
      return R.string.state_downloading;
    case 5:
      return R.string.state_completed;
    case 6:
      return R.string.state_paused_network_unavailable;
    case 7:
      return R.string.state_paused_by_request;
    case 8:
      return R.string.state_paused_wifi_disabled;
    case 9:
      return R.string.state_paused_wifi_unavailable;
    case 10:
      return R.string.state_paused_wifi_disabled;
    case 11:
      return R.string.state_paused_wifi_unavailable;
    case 12:
      return R.string.state_paused_roaming;
    case 13:
      return R.string.state_paused_network_setup_failure;
    case 14:
      return R.string.state_paused_sdcard_unavailable;
    case 15:
      return R.string.state_failed_unlicensed;
    case 16:
      return R.string.state_failed_fetching_url;
    case 17:
      return R.string.state_failed_sdcard_full;
    case 18:
    }
    return R.string.state_failed_cancelled;
  }

  public static String getExpansionAPKFileName(Context paramContext, boolean paramBoolean, int paramInt)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    if (paramBoolean);
    for (String str = "main."; ; str = "patch.")
      return str + paramInt + "." + paramContext.getPackageName() + ".obb";
  }

  public static File getFilesystemRoot(String paramString)
  {
    File localFile1 = Environment.getDownloadCacheDirectory();
    if (paramString.startsWith(localFile1.getPath()))
      return localFile1;
    File localFile2 = Environment.getExternalStorageDirectory();
    if (paramString.startsWith(localFile2.getPath()))
      return localFile2;
    throw new IllegalArgumentException("Cannot determine filesystem root for " + paramString);
  }

  public static String getSaveFilePath(Context paramContext)
  {
    File localFile = Environment.getExternalStorageDirectory();
    return localFile.toString() + Constants.EXP_PATH + paramContext.getPackageName();
  }

  public static String getSpeedString(float paramFloat)
  {
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Float.valueOf(1000.0F * paramFloat / 1024.0F);
    return String.format("%.2f", arrayOfObject);
  }

  public static String getTimeRemaining(long paramLong)
  {
    if (paramLong > 3600000L);
    for (SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault()); ; localSimpleDateFormat = new SimpleDateFormat("mm:ss", Locale.getDefault()))
      return localSimpleDateFormat.format(new Date(paramLong - TimeZone.getDefault().getRawOffset()));
  }

  public static boolean isExternalMediaMounted()
  {
    return Environment.getExternalStorageState().equals("mounted");
  }

  public static boolean isFilenameValid(String paramString)
  {
    String str = paramString.replaceFirst("/+", "/");
    return (str.startsWith(Environment.getDownloadCacheDirectory().toString())) || (str.startsWith(Environment.getExternalStorageDirectory().toString()));
  }

  static String parseContentDisposition(String paramString)
  {
    try
    {
      Matcher localMatcher = CONTENT_DISPOSITION_PATTERN.matcher(paramString);
      if (localMatcher.find())
      {
        String str = localMatcher.group(1);
        return str;
      }
    }
    catch (IllegalStateException localIllegalStateException)
    {
    }
    return null;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.google.android.vending.expansion.downloader.Helpers
 * JD-Core Version:    0.6.2
 */